<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!DOCTYPE html>
<html lang="zh-CN" >

<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/Details.css">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

    <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap-theme.min.css" integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" crossorigin="anonymous">

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
    <title>商城</title>

    <script>
        function AddCollection(uid,pid){
            if(confirm("您确定要收藏吗？")){
                location.href="${pageContext.request.contextPath}/CollectionServlet?action=AddCollection&uid="+uid+"&pid="+pid;
            }
        }

        function addCart(){
            confirm("添加成功!")
        }
    </script>
</head>

<body>
<c:if test="${empty user}">
    <div class="top-nav">
        <div class="container clearf">
            <div class="left">
                <a href="${pageContext.request.contextPath}/Index.jsp" class="item">首页</a>
            </div>

            <div class="right">
                <a href="${pageContext.request.contextPath}/Register.jsp" class="item">注册/登录</a>
            </div>
        </div>
    </div>
</c:if>

<c:if test="${not empty user}">
    <div class="top-nav">
        <div class="container clearf">
            <div class="left">
                <a href="${pageContext.request.contextPath}/UserServlet?action=BackToIndex&id=${user.id}" class="item">首页</a>
            </div>

            <div class="right">
                <div class="dropdown item">
                    <a class="item">欢迎您，${user.username}</a>
                    <div class="dropdown-content">
                        <a href="${pageContext.request.contextPath}/UserServlet?action=UserInf&id=${user.id}">个人信息</a>
                        <a href="#">我的订单</a>
                        <a href="${pageContext.request.contextPath}/CartServlet?action=IntoCart&id=${user.id}">我的购物车</a>
                        <a href="${pageContext.request.contextPath}/CollectionServlet?action=IntoCollection&id=${user.id}">我的收藏夹</a>
                        <a href="${pageContext.request.contextPath}/UserServlet?action=LogOut">退出登录</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</c:if>

<div class="header">
    <div class="container clearf">
        <div class="col-2 logo">商城</div>
        <div class="col-5 search-bar">
            <input type="text">
            <button>搜索</button>
        </div>
    </div>
</div>

<div class="container clearf">
    <div class="col-3 bianju">
        </br>

        <img src="${pageContext.request.contextPath}/img/${product.picture}">
    </div>
    <div class="col-5 title">
        <form action="${pageContext.request.contextPath}/OrdersServlet?action=buynow&pid=${product.id}&uid=${user.id}" method="post">
        <div>${product.name}</div>
        </br>
        <div>价格：${product.price}</div>
        </br>
        <br />
        <br />
        <ul class="btn-numbox">
            <li style="margin-right: 32px"><span class="number">数量</span></li>
            <li>
                <ul class="count">
                    <li><span id="num-jian" class="num-jian">-</span></li>
                    <li><input type="text" class="input-num" id="input-num" value="1" name="buynum"/></li>
                    <li><span id="num-jia" class="num-jia">+</span></li>
                </ul>
            </li>
            <li><span class="kucun">（库存:</span><span class="kucun">${product.num}</span><span class="kucun">)</span></li>
        </ul>
        <div></div>
        <br />
        <div>
            <c:if test="${not empty user}">
                <button type="submit" title="购买" class="An1" style="float: left;margin-left: 10px;">购买</button>

                <a onclick="AddCollection(${user.id},${product.id})" title="购买" class="An1" style="float: left;margin-: 40px;">收藏</a>


            <a onclick="addCart()" href="${pageContext.request.contextPath}/CartServlet?action=AddCart&uid=${user.id}&pid=${product.id}"  title="购买" class="An1" style="float: right;margin-right: 100px;">加入购物车</a>
            </c:if>
                </div>
        </form>
    </div>
</div>
<br />
<hr />


<div id="content" class="active_list ">
    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li class="layui-this">商品详情</li>
            <li>商品评论</li>

        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <img src="${pageContext.request.contextPath}/img/${product.detail}" >

            </div>
            <div class="layui-tab-item">
                <table id="chargeTab" class="table table-hover">
                    <thead>
                    <tr>

                        <th>商品评论详情:</th>

                        <%--<th colspan="8">--%>

                        <c:forEach items="${comment}" var="c" varStatus="i">
                    <tr>
                        <td>${c.username}</td>
                        <td>${c.name}</td>
                        <td>${c.newmsg}</td>
                        <td><c:if test="${not empty c.picture}"><img src="${pageContext.request.contextPath}/img/${c.picture}" width="100" height="100"></c:if></td>
                        <td>${c.newtime}</td>
                        <td>
                            <c:if test="${user.id == c.userid}"><a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/CommentServlet?action=DelComment&uid=${user.id}&id=${c.id}&pid=${product.id}">删除</a></c:if>
                        </td>
                    </tr>
                    <c:if test="${not empty c.remsg}">
                        <tr>
                            <td></td>
                            <td>回复:</td>
                            <td>${c.remsg}</td>
                            <td>${c.retime}</td>
                        </tr>

                    </c:if>
                    </c:forEach>

                    </tr>
                    </thead>
                </table>
            </div>

        </div>
    </div>
</div>
<hr>
<div class="footer">
    <div class="container clearf">
        <div class="">© 2021  版权所有 粤ICP备11111111号 |隐私政策|用户使用协议|资质证照|知识产权</div>
    </div>
</div>
<script>
    var num_jia = document.getElementById("num-jia");
    var num_jian = document.getElementById("num-jian");
    var input_num = document.getElementById("input-num");

    num_jia.onclick = function() {

        if(input_num.value >= ${product.num}) {
            input_num.value = ${product.num};
        } else {

            input_num.value = parseInt(input_num.value) + 1;
        }
    }

    num_jian.onclick = function() {

        if(input_num.value <= 1) {
            input_num.value = 1;
        } else {

            input_num.value = parseInt(input_num.value) - 1;
        }


    }

</script>
</body>

</html>
